class Node:
    def __init__(self,val=0,next=None):
        self.val=val 
        self.next=next

def solve(head1,head2):
    sum,k=0,1
    cur1,cur2=head1,head2 
    while cur1 or cur2:
        if cur1: 
            sum+=k*cur1.val
            cur1=cur1.next 
        if cur2: 
            sum+=k*cur2.val
            cur2=cur2.next
        k*=10
    if sum<10: return Node(sum)
    head=Node(sum%10)
    cur=head
    sum=sum//10 
    while sum>=1:
        cur.next=Node(sum%10)
        sum=sum//10 
        cur=cur.next 
    return head 

def build(lst):
    head=Node(lst[0])
    cur=head
    for i in range(1,len(lst)):
        cur.next=Node(lst[i])
        cur=cur.next 
    return head

def print_node(head):
    cur=head 
    while cur:
        print(cur.val)
        cur=cur.next

l1 = [2,4,3]
l2 = [5,6,4]
head1,head2=build(l1),build(l2)
head=solve(head1,head2)
print_node(head)





